package com.e3.basdoc.cust.model;

import com.e3.basdoc.bank.model.BankModel;
import com.e3.web.core.model.SuperModel;
import com.e3.web.widget.model.ListTypeModel;

public class CustAccountModel extends SuperModel implements CustAccountFields {

	private static final long serialVersionUID = -3906580632887343836L;

	private BankModel bank;

	private Long bankId;
	
	private ListTypeModel<Integer> accountTypeModel;
	
	private Integer accountType;

	public BankModel getBank() {
		return get(CustAccountFields.BANK);
	}

	public void setBank(BankModel bank) {
		set(CustAccountFields.BANK, bank);
		if(bank==null){
			setBankId(0L);
		}
		else{
			setBankId(bank.getId());
		}
	}

	public Long getBankId() {
		if(bankId == null){
			return getRefModelId(CustAccountFields.BANK);
		}
		return bankId;
	}

	public void setBankId(Long bankId) {
		this.bankId = bankId;
	}

	public String getAccountNo() {
		return get(CustAccountFields.ACCOUNTNO);
	}

	public void setAccountNo(String accountNo) {
		set(CustAccountFields.ACCOUNTNO, accountNo);
	}

	public Integer getAccountType() {
		if(accountType==null){
			ListTypeModel<Integer>  model = getAccountTypeModel();
			if(model==null){
				accountType = CustConstant.ACCOUNT_TYPE_COMMON;
			}
			else{
				accountType = model.getValue();
			}
		}
		return accountType;
	}

	public void setAccountType(Integer accountType) {
		this.accountType = accountType;
	}

	protected ListTypeModel<Integer> getAccountTypeModel() {
		return get(CustAccountFields.ACCOUNTTYPE);
	}

	protected void setAccountTypeModel(ListTypeModel<Integer> accountTypeModel) {
		set(CustAccountFields.ACCOUNTTYPE, accountTypeModel);
		if(accountTypeModel!=null){
			setAccountType(accountTypeModel.getValue());
		}
		else{
			setAccountType(CustConstant.ACCOUNT_TYPE_COMMON);
		}
	}

	public boolean isAccountIsDefault() {
		return getBooleanValue(CustAccountFields.ACCOUNTISDEFAULT,false);
	}

	public void setAccountIsDefault(boolean accountIsDefault) {
		set(CustAccountFields.ACCOUNTISDEFAULT, accountIsDefault);
	}

	public String getRemark() {
		return get(CustAccountFields.REMARK);
	}

	public void setRemark(String remark) {
		set(CustAccountFields.REMARK, remark);
	}

	public String toString() {
		return getAccountNo();
	}

}
